home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 283 < prev    next >
Text File  |  1996-08-06  |  2KB  |  64 lines

  1. Path: swidir.switch.ch!epflnews!Thomas.Wolf
  2. From: Thomas.Wolf@di.epfl.ch (Thomas Wolf)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Are macros expanded within unused macro arguments?
  5. Date: 2 Feb 1996 08:36:38 GMT
  6. Organization: Ecole Polytechnique FΘdΘrale de Lausanne
  7. Sender: wolf@lglsun5.epfl.ch (Thomas Wolf)
  8. Message-ID: <4esiem$bbr@info.epfl.ch>
  9. References: <DM3MC3.Atv@scr.siemens.com> <TANMOY.96Feb1102025@qcd.lanl.gov> <4es8rp$98n@usenet.pa.dec.com>
  10. NNTP-Posting-Host: lglsun5.epfl.ch
  11.  
  12. In article <4es8rp$98n@usenet.pa.dec.com>, diamond@tko.dec.com (Norman Diamond) writes:
  13. :> In article <TANMOY.96Feb1102025@qcd.lanl.gov>, tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya) writes:
  14. :> >In article <DM3MC3.Atv@scr.siemens.com> mlg@scr.siemens.com (Michael
  15. :> >Greenberg) writes: 
  16. :> >>Is the following program legal?
  17. :> >>#define foo(unused)
  18. :> >>#define bar(x,y)
  19. :> >>foo(bar(1))
  20. :> 
  21. :> >I read it as being legal.
  22. :> 
  23. :> Mr. Bhattacharya, I am shocked.
  24. :>
  25. [Snip]
  26.  
  27. Mr. Diamond, why are you shocked? Macro 'bar' is not invoked. Read 6.8.3.1
  28. again: we do
  29.  
  30.    - identify the parameters
  31.    
  32.      Ok, 'foo' has one parameter, "bar(1)".
  33.      
  34.    - replace occurrences of the formal parameter ('unused') in the
  35.      replacement list by the corresponding argument after macro re-
  36.      placement within this argument.
  37.      
  38.      Well, 'foo's replacement list is empty, so this never happens.
  39.      In other words, since there's no 'unused' in the replacement
  40.      list, we'll never try to substitute it by the argument "bar(1)",
  41.      thus we'll never try to perform macro replacement on "bar(1)"
  42.      and therefore 'bar' is not invoked.
  43.      
  44. Your quote from 6.8.3 (3.8.3. in ANSI Classic) does not apply:
  45.      
  46. :>       lines 14 to 15:  "The number of arguments in an INVOCATION of a
  47. :>       function-like macro shall agree with the number of parameters in
  48. :>       the macro definition, and [...]"
  49.  
  50. (Emphasis added, TW)
  51.  
  52. Above quote applies only to *invocations*, but since 'bar' is not invoked,
  53. it's irrelevant in this example.
  54.  
  55. Regards,
  56.  
  57.   Thomas
  58. ----------------------------------------------------------------------
  59. Swiss Federal Institute of Technology | Thomas Wolf
  60. Software Engineering Laboratory       | EPFL-DI-LGL
  61. Thomas Wolf (TW)                      | CH-1015 Lausanne (Suisse)
  62. E-Mail: wolf@di.epfl.ch               | Phone: (++41 21)693 42 37
  63. ---------------------------------------------------------------------- 
  64.